<template>
  <su-page bg="#f7f7f7">
    <su-body>
      <!-- header -->
      <su-white-header v-if="detailData" :title="detailData.LCBT" :prop="detailData.createTime"></su-white-header>
      <!-- detail -->
      <su-prop-group title="流程详细信息" v-if="detailData">
        <su-prop label="发起部门">{{detailData.FSDW || ''}}</su-prop>
        <su-prop label="发起人">{{detailData.FSR || ''}}</su-prop>
        <su-prop label="发起时间">{{detailData.FQSJ || ''}}</su-prop>
        <su-prop label="接收部门">{{detailData.JSDW || ''}}</su-prop>
        <su-prop label="接收人">{{detailData.JSR || ''}}</su-prop>
        <su-prop label="意见建议">{{detailData.YJJY || ''}}</su-prop>
      </su-prop-group>
	  <su-prop-group title="附件" v-if="detailData.FJID != null">
		  <view v-for="(item,index) in fileList" :key="index">
			  <view @click="previewImg(index)" :key="index" v-if="item.filename.indexOf('docx') != -1|| item.filename.indexOf('doc') != -1" class="color-primary">{{item.filename || ''}}</view>
			  <image :src="item.imgsrc" class="imgStyle" v-if="item.filename.indexOf('png') != -1"></image>
		  </view>
	    <!-- <text v-for="(item,index) in fileList" :key="index" class="color-primary">{{item.FILENAME || ''}}</text> -->
	  </su-prop-group>
      <!-- loading -->
      <su-list-loading :loading="detailLoading"></su-list-loading>
    </su-body>
  </su-page>
</template>

<script>
/**
  * @Description:发起流程详情
  * @author:神仙姐姐
  * @param 
  * @return 
  * @createTime: 2022-11-22 14:49:13
  * @Copyright by 神仙姐姐
  */
  import {
    mapState
  } from 'vuex'
  import {runSQL,previewPath} from '@/common/utils/wxutils.js'
  export default {
    data() {
      return {
        id:'',
        detailData: [],
        detailLoading: false,
		fileList:[]
      }
    },
    computed: {
      ...mapState(['token'])
    },
    onLoad(params) {
	  let datas = JSON.parse(decodeURIComponent(params.data));
      this.getDetail(datas)
    },
    watch: {
      token(newVal) {
        this.getDetail()
      }
    },
    methods: {
      // 获取详情
      getDetail(datas) {
		this.fileList.length =0;
		this.detailData = datas
		console.log(111)
		console.log(this.detailData)
		console.log(this.detailData.FJID)
		//附件
		if(this.detailData.FJID == null) return
		let filterid = this.detailData.FJID
		if(filterid){
			if(filterid.includes(',')){
				//多个附件
				let id = filterid.split(',')
				for(let b =0;b<id.length;b++){
					runSQL(`select * from ssnydw.tbfile where fileid = '${id[b]}';`).then(ress=>{
						// debugger
						if(ress[0].length>0){
							this.fileList.push({
								imgsrc: previewPath + ress[0][0].FILEID,
								filename : ress[0][0].FILENAME
							})
						}
					})
				}
			}else{
				runSQL(`select * from ssnydw.tbfile where fileid = '${filterid}';`).then(res=>{
					// debugger;
					if(res[0].length>0){
						this.fileList.push({
							imgsrc: previewPath + res[0][0].FILEID,
							filename : res[0][0].FILENAME
						})
					}
				})
			}
		}
      },
	  previewImg(index){
	  	let sthis = this;
	  	wx.downloadFile({
	  	  //文件url
	  	  url: sthis.fileList[index].imgsrc,
	  	  success: function (res) {
	  	    const filePath = res.tempFilePath
	  	    wx.openDocument({
	  	      filePath: filePath,
						fileType: sthis.fileList[index].filename.substring(sthis.fileList[index].filename.lastIndexOf(".")+1),
	  	      success: function (res) {
	  	        console.log('打开文档成功')
	  	      },
	  	      fail: function (res) {
	  	        console.log('打开文档失败')
	  	      },
	  	    })
	  	  }
	  	})
	  },
    },
  }
</script>

<style lang="scss" scoped>
	.imgStyle{
		width: 100%;
		margin-top: 10px;
	}
</style>
